<?php 
	if (isset($_POST['save'])) {
		// Save settings
		include_once "db/db.php";
		mysql_query("
			UPDATE `settings` 
			SET `initialcash` = '" . $_POST['initialcash'] . "',
				`loansize` = '" . $_POST['loansize'] . "',
				`loanpayback` = '" . $_POST['loanpayback'] . "',
				`unifees` = '" . $_POST['unifees'] . "'
			LIMIT 1");
		// Go back to homepage
		header("location:index.php");
	}

	$hide_nav = true;
	include_once "header.php";
	
	$settings = mysql_fetch_assoc(mysql_query("SELECT * FROM `settings` LIMIT 1"));
?>

<script text="text/javascript">
	jQuery(document).ready(function () {
		jQuery("#btnCancel").click(function () {
			window.location = "index.php";
		});
	});
</script>

<h2>Settings</h2>

<form action="settings.php" method="post">
<table>
	<tr>
		<th>Starting cash</th>
		<td>
			<input name="initialcash" value="<?= $settings['initialcash']; ?>" class="money"/>
		</td>
	</tr>
	<tr>
		<th>Loan size</th>
		<td><input name="loansize" value="<?= $settings['loansize']; ?>" class="money"/></td>
	</tr>
	<tr>
		<th>Loan pay-back rate</th>
		<td><input name="loanpayback" value="<?= $settings['loanpayback']; ?>" class="money"/></td>
	</tr>
	<tr>
		<th>Uni fees</th>
		<td><input name="unifees" value="<?= $settings['unifees']; ?>" class="money"/></td>
	</tr>
	<tr>
		<td colspan="2" class="actions">
			<input type="submit" name="save" value="Save"/>
			<input type="reset" value="Cancel" id="btnCancel"/>
		</td>
	</tr>
</table>
</form>

<?php include_once "footer.php"; ?>
